/**
 *Copyright (c) 2017- https://gitee.com/allmx/master.git
 * hhqk-lmx:下午1:13:04
 */
package org.hhqk.admin.login.shiro;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import org.apache.shiro.web.util.WebUtils;

/**
 * @author Administrator
 * Myddd.java
 * 2017年11月17日
 * <p>description:重写FormAuthenticationFilter 是 因为 shiro 配置 successurl的路径会失效
 * 		FormAuthenticationFilter 系统默认的是认证成功后跳转到上一次请求的路径，
 * 		如果是首次请求，那shiro就会跳转到默认虚拟路径“/”，也就是跳转到index.jsp根目录下
 *  </p>
 */
public class MyFormAuthenticationFilter extends FormAuthenticationFilter{

	@Override
	protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest request,
			ServletResponse response) throws Exception {
		boolean contextRelative = true;
		String successUrl = this.getSuccessUrl();
		if("".equals(successUrl)){
		successUrl = DEFAULT_SUCCESS_URL;
		}
		WebUtils.issueRedirect(request, response, successUrl, null, contextRelative);
		return false;
	}
	
}
